﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsInput;

namespace AutoTestSystem
{
    public class StepClass
    {
        public string StepName { get; set; }

        public string StepDetail;


        public string CompareStr { get; set; }

        public string MonitorArea { get; set; }
        public string Area;

       


        public string IsEnable { get; set; }


        public void StepReachMethod(Form1 form)
        {
           
              
                    string[] str = StepDetail.Split('-');
                    for (int j = 0; j < str.Length; j++)
                    {
                        if (str[j].Contains(","))
                        {
                            ToolClass.MoveMouseTo(int.Parse(str[j].Split(',')[0]), int.Parse(str[j].Split(',')[1]));

                            Thread.Sleep(1);
                        }
                        else if (str[j].Contains("S"))
                        {
                            Thread.Sleep(int.Parse(str[j].Substring(1)));
                        }
                        else if (str[j] == "1")
                        {
                            var input = new InputSimulator();
                            input.Mouse.LeftButtonClick().Sleep(1);
                        }
                        else if (str[j] == "3")
                        {
                            var input = new InputSimulator();
                            input.Mouse.RightButtonClick().Sleep(1);
                        }
                        else if (str[j] == "2")
                        {
                            var input = new InputSimulator();
                            input.Mouse.LeftButtonDoubleClick().Sleep(1);
                        }
                        else if (str[j] == "4")
                        {
                            var input = new InputSimulator();
                            input.Mouse.RightButtonDoubleClick().Sleep(1);
                        }
                    }

                
            

            Thread.Sleep(500);

           
               
                    //Bitmap b = ToolClass.GetFile(stepList[i].StepName);
                    string file = null;
                    Bitmap b = ScreenClass.GetFullScreenShot();
                    file = Application.StartupPath + @"\ResultImage\" + DateTime.Now.ToString("yyMMdd-hhmmss") + ".png";
                    //b.Save(file);
                    int tempX = int.Parse(Area.Split(",")[0]);
                    int tempY = int.Parse(Area.Split(",")[1]);
                    int tempWidth = int.Parse(Area.Split(",")[2]);
                    int tempHeight = int.Parse(Area.Split(",")[3]);
                    Bitmap bitmap = ToolClass.CropImage(b, tempX, tempY, tempWidth, tempHeight);
                    bitmap.Save(file);
                    Graphics g = Graphics.FromImage(b);
                    Pen pen = new Pen(Color.Red, 3);
                    g.DrawRectangle(pen, tempX, tempY, tempWidth, tempHeight);
                    form.pictureBox1.BackgroundImage = b;                 
                    form.uiRichTextBox1.Text=ToolClass.OcrCheckMethod(file);
        }

    }



  

}
